package org.jiangy.authentication.config.problem;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Configuration;
import org.zalando.problem.jackson.ProblemModule;
import org.zalando.problem.violations.ConstraintViolationProblemModule;

/**
 * @author <a href="mailto:jiangliu0316@outlook.com" rel="nofollow">蒋勇</a>
 * @see org.jiangy.authentication.config.problem.SecurityExceptionHandler
 * @see org.jiangy.authentication.config.SecurityConfig#securityFilterChain
 * <a href="https://github.com/zalando/problem-spring-web">Problem Spring Web</a>
 * <a href="https://github.com/zalando/problem-spring-web/tree/main/problem-spring-web">Problem Spring Web Config</a>
 * Problem 基础配置：
 * 1. 注册 ProblemModule、ConstraintViolationProblemModule 模块到 ObjectMapper
 * 2. SecurityFilterChain 增加如下配置 @Import(SecurityProblemSupport.class)
 * 3. 创建安全相关的异常创建一个异常处理程序
 * 4. 禁用 SpringMVC 默认白标错误页面，以便我们能够看到我们的自定义错误表示 `@SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)`
 * <code>
 * SecurityProblemSupport problemSupport
 * http.exceptionHandling(handler -> handler
 * .authenticationEntryPoint(problemSupport)
 * .accessDeniedHandler(problemSupport))
 * </code>
 * <p>创建时间: 2024/8/16 </p>
 */
@Configuration
public class ProblemConfig {
    public ProblemConfig(ObjectMapper objectMapper) {
        objectMapper.registerModules(
                new ProblemModule(),
                new ConstraintViolationProblemModule());
    }
}